import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)


//在vue-cli项目中使用vuex
//https://www.jianshu.com/p/cba77015cd47

const store = new Vuex.Store({
  state:{
    name: 'qwerqetdsf',  //存储了1个公共状态name
    age: '23',            //存储了1个公共状态age
    num: 0 , //存储了1个公共状态 num
  },

  getters: {
    //声明vuex getter方法
    forList(state){
      let n=state.num + 1000;
      return n;
    },
    forLive(state){
      let  n =state.num + 900;
      return n;
    },
    getName(state){
      let n=state.name;
      return n;
    }
  },


  //mutation中的方法 用于改变公共状态的值
  mutations:{
    showPeople(state ,msg){
      state.name = msg
    },
    add(state,n){
      state.num+=n;
    },
    del(state,n){
      state.num-=n;
    }
  }

});
export default store
